<?php
declare (strict_types=1);

namespace app\api\controller;

use app\BaseController;
use think\Request;

class Upload extends BaseController
{
    public function logo(Request $request)
    {
        // 接收上传的类型
        $type = $request->post("type", 'goods');
        // 接收文件上传
        $file = $request->file();
        // 设定文件上传的大小
        $fileSize = 10240 * 1024 * 2;
        try {
            // 验证文件上传的大小、后缀
            validate(['logo' => 'fileSize:' . $fileSize . '|fileExt:jpg'])->check($file);
            // 将图片保存至本地
            $files = $request->file('logo');
            $saveName = \think\facade\Filesystem::putFile($type, $files);
            // 将文件上传的路径返回
            return success('uploads/' . $saveName);
        } catch (\think\exception\ValidateException $e) {
            return fail($e->getMessage());
        }
    }

    public function img(){

    }
}
